package task20;

import java.util.Scanner;

/**
 * @author Administrator
 * 抛出异常
 */
public class ThrowsTest {
    public static void main(String[] args) {
        System.out.println("请输入被除数：");
        Scanner scanner=new Scanner(System.in);
        int a=scanner.nextInt();
        System.out.println("请输入除数：");
        int b=scanner.nextInt();
        // 调用方法完成除法,一种是用户主动加try catch
        // 另一种：强制用户必须加try catch (方法后加throws Exception)
        int result= 0;
        try {
            result=Divide.myDivide(a,b);
        } catch (Exception e) {
            e.printStackTrace();
        }

       /* try {
            result = Divide.myDivide(a,b);
            System.out.println("结果是："+result);
        } catch (Exception e) {
            System.out.println("异常是："+e.getMessage());
        }finally {
            System.out.println("可写可不写，都会执行");
        }*/

        // 使用自定义异常的方法
        try {
            result=Divide.myDivide2(a,b);
            System.out.println("结果是："+result);
        } catch (MyDivideException e) {
            System.out.println(e.getMessage());
        }

    }
}
